﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Web._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .rpanel{ width:250px; float:left;}
    </style>
    <script type="text/javascript"  src="js/jquery-1.2.6.js"></script>
    <script type="text/javascript" >
    
        String.prototype.format = function()
        {
            var args = arguments;
            return this.replace(/\{(\d+)\}/g,               
                function(m,i){
                    return args[i];
                });
        }
        
        var s_monster ="{0}减少{1}血，剩余{2}<br />";
        var s_charactor = "{0}减少{1}血，剩余{2}<br />";
        var s_dead ="{0}死亡！";
        var s_getitem ="发现{0}！";
        var s_nothing ="什么都没发现！";
        
        var cock = {"health":20,"attack":5,"defense":5};
        var role = {"health":30,"attack":5,"defense":5};
        
        var attack = function(){
            $.getJSON("gate/battle1.ashx",
                {"id":"18890420","action":"attack","_cha":18890420,"_mon":20080317},
                function(json){
                    if(json.Mon.Health==0)
                        $("#mon").append(s_dead.format("鸡"));
                    else
                        $("#mon").append(s_monster.format("鸡",json.Mon.Hurt,json.Mon.Health));
                        
                    if(json.Cha.Health==0)
                        $("#cha").append(s_dead.format("武士"));
                    else
                        $("#cha").append(s_charactor.format("武士",json.Cha.Hurt,json.Cha.Health));
                }
            );
        };
        
        var getitem = function(){
            $.getJSON("gate/battle1.ashx",
                {"id":"18890420","action":"getitem","_cha":18890420,"_mon":20080317},
                function(json){
                    if(json.Item=="-1")
                        $("#mon").append(s_nothing);
                    else
                        $("#mon").append(s_getitem.format(json.Item));
                   
                }
            );
        };
        
        
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="width:600px; position:relative;">
    <h1>result:</h1>

    <div id="mon" class="rpanel"></div>
    </div>
        <div id="cha" class="rpanel">
        
    </div>
    <div>
    <div>鸡</div>
    <a onclick="attack()">攻击</a>
    <a onclick="getitem()">挖取</a>
    </div>
    </form>
</body>
</html>
